package com.zhengqing.design.action.iterator._01;

public class NameRepository implements Container {
    public String[] names = {"a", "b", "c", "d"};

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements Iterator {

        int index;

        @Override
        public boolean hasNext() {
            if (this.index < NameRepository.this.names.length) {
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if (this.hasNext()) {
                return NameRepository.this.names[this.index++];
            }
            return null;
        }
    }
}